package com.example.wangfanwangluo.wangfanboss;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;

import com.example.wangfanwangluo.wangfanboss.Adapters.PeizaiyundanAdapter;
import com.example.wangfanwangluo.wangfanboss.Models.PeizaiyundanModel;
import com.example.wangfanwangluo.wangfanboss.Models.PeizaizhongzhuanModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanghouyi on 2017/11/29.
 */

public class PeizaiyundanActivity extends AppCompatActivity {


    private String title;
    private ListView lv;
    private PeizaiyundanAdapter adapter;
    private List<Object> list = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_peizai);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null){
            actionbar.hide();
        }
        Intent intent = getIntent();
        this.title = intent.getStringExtra("title");

        //标题
        changeTitle();

        //返回按钮
        backAction();
        //数据
        loadData();
        //视图，传递数据
        initViews();
    }


    private void loadData() {
        for (int i = 0; i < 10; i++) {
            PeizaiyundanModel firstModel = new PeizaiyundanModel("运单号：DJFGHJHHK121212212+"+String.valueOf(i),"乌鲁木齐","拉萨",
                    "张晓丽","王晓静", "衣服","12/31 10：00","已配载");
            list.add(firstModel);

            PeizaizhongzhuanModel secondModel = new PeizaizhongzhuanModel("运单号：DJFGHJHHK121212212+"+String.valueOf(i),"乌鲁木齐",
                    "拉萨", "张晓丽","王晓静", "衣服","12/31 10：00","已配载","运单号(中转)：BMWRIWIQIWZQWEQQEW","北京",
                    "上海", "李雷","韩梅梅", "裤子","01/31 10：00","待配载");
            list.add(secondModel);

        }
    }

    private void initViews() {
        //listview
        adapter = new PeizaiyundanAdapter(this,list);
        lv = (ListView)findViewById(R.id.peizaiyundan_listview);
        lv.setAdapter(adapter);
//        adapter.setObjOnDetailPushListener(new KucunDetailAdapter.onDetailPushListener() {
//            @Override
//            public void onDetailPushListener(int i) {
//                //进入详情页面
//                Intent intent = new Intent(KucunDetailActivity.this,DocumentDetail.class);
//                Bundle bundle = new Bundle();
//                bundle.putString("type", "detail");
//                intent.putExtras(bundle);     //将bundle传入intent中。
//                startActivity(intent);
//                Toast.makeText(KucunDetailActivity.this,"第" + i + "条item被点击", Toast.LENGTH_SHORT).show();
//            }
//        });
    }

    private void changeTitle() {
        TextView textView = (TextView)findViewById(R.id.peizaiyundan_title);
        textView.setText(this.title + "所配载运单");
    }

    public void backAction(){
        TextView textView = (TextView)findViewById(R.id.peizaiyundan_back);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}
